package org.dllwh.alibaba.nacos.plugin.datasource.impl.base;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import org.dllwh.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
import org.dllwh.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName BaseTenantCapacityMapper
 * @Description BaseTenantCapacityMapper的基本实现。
 * @Date 2024-11-23 12:26
 * @版本 V 1.0.1
 * @since JDK 17
 */
public class BaseTenantCapacityMapper extends TenantCapacityMapperByMySql {
    
    private DatabaseDialect databaseDialect;
    
    public BaseTenantCapacityMapper() {
        databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
    }
    
    @Override
    public MapperResult getCapacityList4CorrectUsage(MapperContext context) {
        String sql = databaseDialect.getLimitTopSqlWithMark("SELECT id, tenant_id FROM tenant_capacity WHERE id>?");
        return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
                context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
    }

}
